#!/usr/bin/env node

const inquirer = require('inquirer');
const fs = require('fs');
const path = require('path');
const ejs = require('ejs');
inquirer.prompt({
    type:"input",
    name:"name",
    message:"Projcet name?"
})
.then(answer=>{
    //模板目录
    const temDir = path.join(__dirname,'templates');
    //目标路径
    const destDir = process.cwd();
    fs.readdir(temDir,(err,files)=>{//文件名， 文件夹下的所有文件
        if(err) throw err;
        files.forEach(item => {
            ejs.renderFile(path.join(temDir,item),answer,(err,result)=>{//ejs模板渲染
                if(err) throw err;

                fs.writeFileSync(path.join(destDir,item),result)
            })
        })
    })

})